/*
 * @Descripttion: 检查任务页面
 * @version: 
 * @Author: linPing
 * @Date: 2019-10-29 12:25:00
 * @LastEditTime: 2019-11-01 15:24:16
 */



import React, { Fragment } from 'react';

import { observer, inject } from 'mobx-react';
import NavigationBar from '../../common/NavigationBar';
import GlobalStyles from "../../res/styles/GlobalStyles";
import { ButtonGroup } from 'react-native-elements'
import FlatListComponent from '../../common/FlatList'
import NavigationUtil from '../../navigator/NavigationUtil'
import ViewUtil from "../../util/ViewUtil";
import SafeAreaViewPlus from "../../common/SafeAreaViewPlus";
import VisibleView from "../../common/VisibleView";
import {
    SafeAreaView,
    StyleSheet,
    ScrollView,
    TouchableOpacity,
    Button,
    View,
    Text,
    StatusBar,
    FlatList
} from 'react-native';


// import { TouchableOpacity } from 'react-native-gesture-handler';

const LIST_GROUP = {
    inspectionRecord: 'inspectionRecord',
    rectificationRecord: 'rectificationRecord',
}


@inject('appStore')
@observer
export default class TaskRoomList extends React.Component {
    constructor(props) {
        super(props)

        this.params = this.props.navigation.state.params

        this.originalData = this.params.item
        this.title = this.originalData.title
        this.state = {
            isLoading: false, //下拉刷新loading
            loadMore:false, //是否还有数据
            hideMore:true, //是否隐藏分页
            dataList: this.originalData.room
        }

    }


    _renderItem(data) {
        const { item } = data

        return <TouchableOpacity
                    onPress={() => {
                        NavigationUtil.goPage({ item }, "TaskRoomDetail")
                    }}
                >
            <View style={[styles.itemBox]}>
                <View style={styles.row}>
                    <Text style={styles.title}>{item.title}</Text>
                    {item.status === 0 && <Text style={[styles.itemText, GlobalStyles.status.primary]}>未检查</Text>}
                    {item.status === 1 && <Text style={[styles.itemText, GlobalStyles.status.warning]}>待提交</Text>}
                    {item.status === 2 && <Text style={[styles.itemText, GlobalStyles.status.info]}>已提交</Text>}
                </View>
                <View style={styles.row}>
                    <View style={styles.rowItem}>
                        <Text style={[styles.itemLabel, GlobalStyles.marginRight10]}>房间负责人</Text>
                        <Text style={styles.itemText}>{item.managerName}</Text>
                    </View>
                    <View style={styles.rowItem}>
                        <Text style={[styles.itemLabel, GlobalStyles.marginRight10]}>安全等级</Text>
                        <Text style={styles.itemText}>{item.level}</Text>
                    </View>
                    <View style={styles.rowItem}>
                        <Text style={[styles.itemLabel, GlobalStyles.marginRight10]}>发现隐患数</Text>
                        <Text style={styles.itemText}>{item.hiddenNum}</Text>
                    </View>
                </View>
            </View>

        </TouchableOpacity>
    }


    _onRefresh(callback) {
        callback()
    }

    _onLoadMore(pageIndex) {
        this.pageIndex = pageIndex
        this.setState({
            data: this.state.data.concat(originalData.items)
        })
    }
    onBack = () => {
        NavigationUtil.goBack(this.props.navigation);
    }


    render() {
        const { navigation } = this.props
        const { appStore, appStore: { theme } } = this.props

        let statusBar = {
            backgroundColor: theme,
            barStyle: 'light-content',
        };
        let navigationBar =
            <NavigationBar
                title={this.title}
                statusBar={statusBar}
                leftButton={ViewUtil.getLeftBackButton(() => this.onBack())}
                style={{ backgroundColor: theme }}
            />;

        const item = this.originalData

        return (

            <SafeAreaViewPlus style={GlobalStyles.root_container}>
                {navigationBar}

                <FlatList
                    data={this.state.dataList}
                    renderItem={data => this._renderItem(data)}
                   
                />
            </SafeAreaViewPlus>
        )
    }

};

const styles = StyleSheet.create({

    container: {
        flex: 1
    },
    header_container: {
        padding: 20,
        backgroundColor: '#fff',
        marginBottom: 20
    },
    info: { paddingTop: 20 },
    itemBox: {
        padding: 20,
        paddingBottom: 10,
        backgroundColor: '#fff',
        marginBottom: 10,

    },
    title: {
        color: "#333"
    },
    row: {
        alignItems: 'center',
        flexDirection: "row",
        justifyContent: "space-between",
        marginBottom: 10
    },
    itemText: {
        fontSize: 12,
        color: "#666"
    },
    desc: {
        fontSize: 11,
        color: "#aaa"
    },
    rowItem: {
        flexDirection: "row",
    },
    list_container: {
        padding: 20,
        paddingBottom: 0,
        backgroundColor: '#fff'
    },
    list_title: {
        backgroundColor: '#fff',
        marginBottom: 10,
    },
    itemLabel: {
        fontSize: 12,
        color: "#aaa"
    }


});

